class Solution {
    int dx[4] = { 0, 0, 1, -1 }, dy[4] = { 1, -1, 0, 0 }, m, n, start;
    void dfs(vector<vector<int>>& image, int sr, int sc, int color)
    {
        image[sr][sc] = color;
        for(int k = 0; k < 4; k++)
        {
            int x = sr + dx[k], y = sc + dy[k];
            if(x >= 0 && x < m && y >= 0 && y < n && image[x][y] == start)
                dfs(image, x, y, color);
        }
    }
public:
    vector<vector<int>> floodFill(vector<vector<int>>& image, int sr, int sc, int color) {
        if(image[sr][sc] == color)
            return image;
        m = image.size(), n = image[0].size(), start = image[sr][sc];
        dfs(image, sr, sc, color);
        return image;
    }
};